#include <linux/fs_struct.h>

void set_fs_root(struct fs_struct *fs, struct path *path)
{
	printf("this is %s(): %d\r\n", __func__, __LINE__);
	// struct path old_root;

	// write_lock(&fs->lock);
	// old_root = fs->root;
	fs->root = *path;
	// path_get(path);
	// write_unlock(&fs->lock);
	// if (old_root.dentry)
		// path_put(&old_root);
}

void set_fs_pwd(struct fs_struct *fs, struct path *path)
{
	printf("this is %s(): %d\r\n", __func__, __LINE__);
	// struct path old_pwd;

	// write_lock(&fs->lock);
	// old_pwd = fs->pwd;
	fs->pwd = *path;
	// path_get(path);
	// write_unlock(&fs->lock);

	// if (old_pwd.dentry)
		// path_put(&old_pwd);
}

struct fs_struct *copy_fs_struct(struct fs_struct *old)
{
	// struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
	struct fs_struct *fs = kmalloc(sizeof(struct fs_struct));
	/* We don't need to lock fs - think why ;-) */
	if (fs) {
		fs->users = 1;
		fs->in_exec = 0;
		// rwlock_init(&fs->lock);
		fs->umask = old->umask;
		// read_lock(&old->lock);
		fs->root = old->root;
		// path_get(&old->root);
		fs->pwd = old->pwd;
		// path_get(&old->pwd);
		// read_unlock(&old->lock);
	}
	return fs;
}

struct fs_struct init_fs = {
	.users		= 1,
	// .lock		= __RW_LOCK_UNLOCKED(init_fs.lock),
	.umask		= 0022,
};
